package com.control.servlet;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UsersDao;
import com.entity.Users;

@WebServlet("/UsersServlet")
public class UsersServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public UsersServlet() {
        super();
    }

	protected void doGet(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException {
		System.out.println("执行servlet了...");
		rep.setContentType("text/html;charset=\"UTF-8\"");
		rep.setCharacterEncoding("UTF-8");
		UsersDao userDao=new UsersDao();
		Users user=new Users();
		List<Users> userList=userDao.sqlQuery(user);
		String msg="<table border='1'>";
		for (Users users : userList) {
			msg+="<tr><td style='border:solid 1px'>"
					+ users.getId() 
					+ "</td><td style='border:solid 1px'>"
					+ users.getName()
					+ "</td><td style='border:solid 1px'>"
					+ users.getSex()
					+"</td></tr>";
		}
		msg+="</table><script>"
				+ "window.onload=function(){"
				+ "alert('123');}"
				+ "</script>";
		Writer out=rep.getWriter();
		out.write(msg);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
